import Author

class AuthorController {

    def scaffold = Author

    def about = {
        [author: Author.get(params?.id)]
    }

    def searchUser = {
        def searchKey = params.searchKey
        def authorInstanceList = new ArrayList()
        if(searchKey){
            authorInstanceList = Author.withCriteria() {
                like('name', '%'+searchKey+'%')
            }
        }
        render(view:'list',model:[authorInstanceList: authorInstanceList])
    }

     // 开启和关闭用户登录权限
    def goswitch = {
        if (params.id) {
            def author = Author.get(params.id)
            author.enabled = !author.enabled
            author.save(flush: true)
        }
        redirect(action: "list" , controller: "author")
    }

    def changeClassesMasterTeacher = {
        def classerList = Classer.findAllByHostId(params.classesId)
        classerList.each{
            it.master = params.masterId.toLong()
            
            if (parent.hasErrors() || !it.save(flush:true)) {
                return ['success':false,'message' : '更改班级班主任失败！']
            }else{
                return ['success':true,'message' : '更改班级班主任成功！']
            }   
        }
    }



}
